import React, { useEffect, useState } from 'react'
import { useLocation } from "react-router-dom"
import axios from '../../http'
import "./detail.css"
export default function index() {
    let obj = useLocation()
    let params: any = {}
    // "?pwd=123&email=1233"
    let arr = obj.search.split("?")[1].split("&")
    for (let i = 0; i < arr.length; i++) {
        let arr2 = arr[i].split("=")
        params[arr2[0]] = arr2[1]
    }
    console.log(params)

    let [goods, setGoods] = useState<any>({})

    useEffect(() => {
        // console.log(obj)


        // xhr.open("GET","url?cout=123&asdf=124",true)
        // xhr.send("email=123&pwd=123")

        axios.get("/egg/detail", { params: { gid: params.gid } })
            .then(res => {

                console.log(res)
                setGoods(res.data.info)

            })

        showreport(0)

    }, [])


    let [arr2, changearr2] = useState<any>([])
    let showreport = async (start) => {
        let res = await axios.get("/egg/getreport", { params: { start, gid: params.gid } })
        console.log(res, "123444444444444444444444444444")
        changearr2(arr2.concat(res.data.info))
    }
    let [reporttext, setreporttext] = useState("")
    let setreport = async () => {
        let res = await axios.get("/egg/setreport", { params: { reporttext, gid: params.gid } })
        console.log(res)
    }
    return (
        <div>
            <h1>{goods.title}</h1>
            <img src={goods.img} alt="" />
            <p>{goods.price}</p>

            <hr />

            <textarea name="" id="" cols="100" rows="10" value={reporttext} onChange={(e) => setreporttext(e.target.value)}></textarea>
            <button onClick={setreport}>提交</button>
            <div>
                {
                    arr2.map((el: any) => (<div key={el.rid}>
                        <h1>
                            <img className='touxiang' src={(axios as any).base + el.img} alt="" />
                            <span>{el.TEXT}</span>
                        </h1>
                    </div>))
                }
            </div>

        </div>
    )
}
